<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注销用户</title>
    <!--bootstrap-->
    <link href="/shop-app/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="/shop-app/js/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="/shop-app/bootstrap/js/bootstrap.min.js"></script>
    <!-- 引入HttpUtil.js -->
    <script src="/shop-app/js/HttpUtil.js"></script>
    <!--引入存到浏览器的js文件-->
    <script src="/shop-app/js/UserCacheUtil.js"></script>
    <!-- 界面报icon找不到问题 -->
    <link rel="shortcut icon" href="#"/>
</head>
<body>

<blockquote class="text-primary">
    <p>注销用户 </p>
</blockquote>
<hr>


<!-- 短信验证 -->
<div class="container" id="div-hide-by-sms">
    <div class="row">
        <div class="col-md-8 col-md-offset-2  col-lg-8 col-lg-offset-2 ">
            <form class="form-horizontal">

                <div class="form-group">
                    <label class="col-sm-3 control-label">用户名</label>
                    <div class="col-sm-7">
                        <input id="smsName" type="text" class="form-control" placeholder="userName">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">电话</label>
                    <div class="col-sm-7">
                        <input id="uPhone"  type="text" class="form-control" placeholder="telephone">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">短信验证</label>
                    <div class="col-sm-7">
                        <input id="noteCode" name="noteCode" type="text" class="= form-inline" placeholder="验证码">
                        <button type="button" id="noteCodeBtn" onclick="submitSms()" class="btn btn-danger">获取短信验证码
                        </button>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-1  col-sm-12">
                        <button onclick="smsLogout()" type="button" class="btn btn-default btn btn-danger smsLogoutBtn"
                                style="width: 120px" disabled="disabled">注销！
                        </button>
                        <button type="reset" class="btn btn-default col-sm-offset-3 btn btn-warning resetBtn"
                                style="width: 120px">重置
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script>

    let uNameEE = $("#smsName");
    let uPhoneEE = $("#uPhone");
    let uName;
    let uPhone;

    let loginUser = getLocalStorage("loginUser");
    console.log(loginUser);


    $(function () {
        let loginUser = getLocalStorage("loginUser");
        //重置数值
        $('.resetBtn').click();
        //渲染默认值
        $('#uPhone').attr('placeholder',loginUser.uPhone);
        $('#smsName').attr('placeholder',loginUser.uName);


        //  动态改变值
        uNameEE.blur(function () {
            if (this.value!="")
                uName = this.value
        });
        uPhoneEE.blur(function () {
            if (this.value!="")
                uPhone = this.value
        })

    });


    //发送短信验证
    function submitSms() {
        console.log(uName);
        if (uName == undefined) {
            uName = loginUser.uName;
        }
        if (uPhone == undefined) {
            uPhone = loginUser.uPhone;
        }

        //ajax 请求后台发送短信
        let url = "/user/submitSms";
        // let url = "/user/submitSmsNo";
        let params = {
            uName: uName,
            uPhone: uPhone
        };
        console.log(params);

        httpPostApi(url, params, function (data) {
            //短信发送成功
            alert(data)
            //设置按钮可点击
            $('.smsLogoutBtn').attr('disabled', false);
        });
    }

    //注销用户
    function smsLogout() {

        if (confirm("确认注销？？") == true) {
            //ajax 请求后台
            let url = "/user/logoutUser";
            let params = {
                uId: loginUser.uId,
                uName: uName,
                uPhone: uPhone,
                noteCode: $("#noteCode").val(),
            };
            console.log(params);
            httpPostApi(url, params, function (data) {
                //删除本地信息
                removeLocalStorage("loginUser");
                console.log(data);
                //请求注册成功转跳到首页
                window.parent.location.href = "/shop-app/index.html";
            });
        }


    }





</script>


</body>
